<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<script language ="javascript" type = "text/javascript" >
    function submitForm(pageNumber)
    {
       $("input#pageNum").val(pageNumber);
       $("#searchForm").submit();
    }
</script>
<form action="<c:url value='/search' />" method="get" id="searchForm">
	<input type="text" name="term" value="<c:out value='${searchRequest.term}'/>"/>
	<form:errors path="searchRequest.term"/>
	<br/>
	<select name="type" >
		<option  value="">Select Search Type</option> 
		<c:forEach var="searchType" items="${searchTypes}">
			<option  value="${searchType}" <c:if test="${searchType == searchRequest.type}">selected</c:if>>
				<c:out value="${searchType}"/>
			</option> 
		</c:forEach>
	</select> 
	<br/>
	<input type="hidden" name="pageNum" id="pageNum"  value="0"/>
	<input type="submit"/> 
</form>
<c:if test="${searchRequest.pageNum > 0}">
	<a href="#" onclick="submitForm(${searchRequest.pageNum-1})"><<< Previous Page</a> | 
</c:if>
<c:if test="${endNum < netflixCatalogTitles.numberOfResults}">
<a href="#" onclick="submitForm(${searchRequest.pageNum+1})">Next Page>>></a> 
</c:if>	

<c:if test="${netflixPeople != NULL}">
Number of results:<c:out value="${netflixPeople.numberOfResults}"/><br/>
<c:forEach var="person" items="${netflixPeople.netflixPersons}">
	<c:out value="${person.name}"/><br/>
	<c:out value="${person.bio}" escapeXml="false"/><br/><br/>
</c:forEach>
</c:if>


<c:if test="${netflixCatalogTitles != NULL}">
	<c:out value="${startNum}"/> to <c:out value="${endNum}"/> of <c:out value="${netflixCatalogTitles.numberOfResults}"/><br/>
		<c:forEach var="netflixCatalogTitle" items="${netflixCatalogTitles.netflixCatalogTitles}">
			<br/><img src="<c:out value='${netflixCatalogTitle.boxArt.medium}'/>"/><br/>
			Title:<c:out value="${netflixCatalogTitle.title.shortTitle}"/><br/>
			Average Rating:<c:out value="${netflixCatalogTitle.averageRating}" /><br />
			<c:url value='/videodetails' var="video">
				<c:param name="movieSeriesId" value="${netflixCatalogTitle.movieSeriesId}" />
				<c:param name="movieSeriesType" value="${netflixCatalogTitle.movieSeriesType}" />
			</c:url>
			Synopsis:<c:out value="${netflixCatalogTitle.synopsis}" escapeXml="false"/><br/>
			
			<a href="${video}">Details</a><br/><br/>
		</c:forEach>
</c:if>
